local skill = fk.CreateSkill {
  name = "ling__groom_and_drill_skill",
}

Fk:loadTranslationTable{
  ["#ling__groom_and_drill-prey"] = "厉兵秣马：获得其中一张牌",
  ["#ling__groom_and_drill-give"] = "厉兵秣马：你可以将一张牌交给一名其他角色，若为装备其可以使用之",
  ["#ling__groom_and_drill-use"] = "厉兵秣马：你可以使用%arg",
}

skill:addEffect("cardskill", {
  prompt = "#ling__groom_and_drill_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = Util.CanUseToSelf,
  on_effect = function(self, room, effect)
    local player = effect.to
    local choice = room:askToChoice(player, {
      choices = { "weapon", "equip_horse" },
      skill_name = skill.name,
    })
    local cards = {}
    if choice == "weapon" then
      cards = room:getCardsFromPileByRule(".|.|.|.|.|weapon", 2)
    else
      cards = room:getCardsFromPileByRule(".|.|.|.|.|offensive_ride,defensive_ride", 2)
    end
    if #cards > 0 then
      local card = room:askToChooseCard(player, {
        target = player,
        flag = { card_data = {{ skill.name, cards }} },
        skill_name = skill.name,
        prompt = "#ling__groom_and_drill-prey",
      })
      room:obtainCard(player, card, true, fk.ReasonJustMove, player, skill.name)
      if player.dead then return end
    end
    if not player:isNude() and #room:getOtherPlayers(player, false) > 0 then
      local to, card = room:askToChooseCardsAndPlayers(player, {
        min_card_num = 1,
        max_card_num = 1,
        min_num = 1,
        max_num = 1,
        targets = room:getOtherPlayers(player, false),
        skill_name = skill.name,
        prompt = "#ling__groom_and_drill-give",
        cancelable = true,
      })
      if #to > 0 and #card > 0 then
        to = to[1]
        card = card[1]
        room:obtainCard(to, card, true, fk.ReasonGive, player, skill.name)
        if not table.contains(to:getCardIds("h"), card) or to.dead then return end
        if Fk:getCardById(card).type == Card.TypeEquip then
          room:askToUseRealCard(to, {
            pattern = {card},
            skill_name = skill.name,
            prompt = "#ling__groom_and_drill-use:::"..Fk:getCardById(card):toLogString(),
          })
        end
      end
    end
  end,
})

skill:addAI(nil, "__card_skill")
skill:addAI(nil, "default_card_skill")

return skill
